package com.example.springboot.demo.poi;

import com.yix.util.DocTemplateGenerator;
import lombok.var;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr;

import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class DocTest {

    public static void main(String[] args) throws Exception {
        String tempFileName = "变更工程量及费用审核单" + UUID.randomUUID().toString() + ".docx";
        List<String[]> partDetail = new ArrayList<>();
        int index = 0;
        if (index < 10) {
            for (; index < 10; index++) {
                String[] row = {
                        "",//子目号
                        "", "@@合并", "@@合并", "@@合并",//子目名称
                        "",//单位
                        "", "@@合并", "@@合并",//变更工程量增减
                        "", "@@合并", //单价
                        "", "@@合并"//变更金额增减
                };
                partDetail.add(row);
            }
        }

        DocTemplateGenerator.open("bgsq_gcl_fyshd.docx")
                .insertMap(1, 4, partDetail, (cell -> {
                            cell.getParagraphs().forEach(paragraph -> {
                                if (paragraph.getRuns().isEmpty()) {
                                    var run = paragraph.createRun();
                                    paragraph.addRun(run);
                                }
                                paragraph.getRuns().forEach(run -> {
                                    //run =paragraph.createRun();
                                    run.setFontSize(8);
                                    CTFonts font = run.getCTR().addNewRPr().addNewRFonts();
                                    //中文
                                    // font.setEastAsia("仿宋"); //改变中文字体设置这个
                                    // ASCII
                                    //font.setAscii("仿宋");//改变数字或者英文字体需要设置这个
                                    font.setAscii("仿宋");
                                    font.setEastAsia("仿宋");
                                    font.setHAnsi("仿宋");
                                    font.setCs("仿宋");
                                    // run.setFontFamily("仿宋");
                                });
                            });
                        }),
                        row -> {
                            CTTrPr trPr = row.getCtRow().addNewTrPr();

                            CTHeight ht = trPr.addNewTrHeight();

                            ht.setVal(BigInteger.valueOf(640));
                        })
                .setApplyFont(true).save(tempFileName);



    }

}
